package ll.sms.socket.protocol;

import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;


public final class Head implements BusinessCode{
	public static final String REQUEST="0";
	public static final String RESPONSE="1";
	private static final  Pattern p = Pattern.compile("^[0-1][1-8][1-9]$");

	public Head(String type , String businessCode){

	}

	public static  String getHead(String type , String businessCode){
		return type+businessCode;
	}

	public static  String getRequestHead(String businessCode){
		return getHead(REQUEST,businessCode);
	}

	public static  String getResponseHead(String businessCode){
		return getHead(RESPONSE,businessCode);
	}

	public static boolean isErrorHead(String headCode){
		 return !p.matcher(headCode).matches();
	}

	public boolean check_R_BCode(String checkString , String businessCode){
		return StringUtils.equals(checkString, getRequestHead(businessCode));
	}

	public boolean check_P_BCode(String checkString , String businessCode){
		return StringUtils.equals(checkString, getResponseHead(businessCode));
	}

	public String toHead(String type , String businessCode){
		return getHead(type, businessCode);
	}

	public static void main(String[] args) {
		System.out.println(isErrorHead("011"));
	}


	public static String  requestToResponse(String requestHead){
		return Head.RESPONSE+requestHead.substring(1);
	}
}
